import { Center } from './center-model.js';
var center = new Center();
Page({
  data: {
    log:[],
    page:1,
    hiddenNullData:true,
    hiddenNomore: true,
    hiddenLoading: true,
    onLoading:false,
    nomore: false,
  },
  onLoad: function (options) {
    this.getInfo();
    this.getLog()
  },
  //获余额明细
  getLog:function() {
    //是否正在加载数据或已加载完全部数据
    if (this.data.onLoading || this.data.nomore) {
      return false;
    }
    var that = this;
    var args = {
      page : this.data.page,
      change_type : 2
    }
    
    //显示正在加载中
    this.setData({
      hiddenLoading : false
    })
    this.data.onLoading = true;
    center.getAccountsList(args, (data) => {
      that.data.onLoading = false;
      var log = that.data.log.concat(data.items);
      that.setData({
        log
      })
      //隐藏正在加载中
      that.setData({
        hiddenLoading: true
      })
      if(log.length == 0){
        //显示没有数据
        that.setData({
          hiddenNullData: false
        })
      }
      if (that.data.page >= data._meta.pageCount){
        that.data.nomore = true;
        if(that.data.page > 1){
          //显示没有更多
          that.setData({
            hiddenNomore: false
          })
        }
      }
      
    });
  },
  //余额总数
  getInfo: function () {
    var that = this;
    var args = {}
    center.index(args, (data) => {
      that.setData({
        item: data.item
      })
    });
  },
  //跳转到充值页面
  toRecharge:function(){
    wx.navigateTo({
      url: 'recharge',
    })
  },
  //跳转到提现页面
  toWithdrawCash: function () {
    wx.navigateTo({
      url: 'withdraw-cash',
    })
  },
  //触底加载更多
  onReachBottom: function () {
    this.data.page++;
    this.getLog();
  },


})